#!/usr/bin/env bash
set -e

cd $BUILD
tag=v$(cat Dockerfile | grep '^ENV VERSION' | cut -d" " -f3)
MESSAGE="New release ${tag}"

# This script creates a release tag

if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then
    echo -e ' - Tag already exists...'
	git tag -d $tag
	git push origin :refs/tags/$tag
	git tag -a $tag -m "$MESSAGE"
	git push origin $tag
else
  echo "===> creating new tag: $tag"
	git tag -a $tag -m "$MESSAGE"
	git push origin $tag
fi
